import smtplib
from email.utils import formataddr
from email.mime.text import MIMEText

with open('/Users/qts/Downloads/interfaceTest/result/20190301110652/report.html', 'rb') as fp:   #读取文件内容
    msg=MIMEText(fp.read(), 'HTML', 'utf-8')   #创建消息对象


msg['Subject'] = "接口自动化报告"
msg['From'] = formataddr(["陈驰","chenchi@qtshe.com"])
msg['To'] = formataddr(["陈驰","chenchi@qtshe.com"])

try:
    server = smtplib.SMTP() # 创建一个 SMTP() 对象
    server.connect("smtp.qtshe.com", "80") # 通过 connect 方法连接 smtp 主机
    #server.starttls() # 启动安全传输模式
    server.login("chenchi@qtshe.com","cnp200@HW") # 邮箱账号登录校验
    server.sendmail("chenchi@qtshe.com","chenchi@qtshe.com", msg.as_string()) # 邮件发送
    server.quit() # 断开 smtp 连接
    print("邮件发送成功！")
except Exception as e:
    print('失败：'+str(e))